// pages/home/home.js
Page({
  onLoad() {
    let thiss = this
    let timer = setInterval(function() {
      const shopData = getApp().globalData.shopData;
      const iconData = getApp().globalData.iconData;
      if (shopData.length > 0 && iconData.length>0) {
        // 数据成功加载清除定时器
        clearInterval(timer);
        thiss.setData({
          iconList:iconData,
          shopList: shopData
        });
        // 数据加载完成后调用 getPhone 函数
        thiss.getPhone();
      }
    }, 100);
  },
  data: {
    shopList:[], //所有手机的数据
    iconList:[], //分类图标
    phoneList:[], //小米手机
    phonesList:[], //华为手机
    
  },
    // 跳转到详细页面
    getDetail(e){
      console.log(e.currentTarget.dataset.id);
      let shopId = e.currentTarget.dataset.id
      let shopList = this.data.shopList.filter(item => item.id == shopId)
      // console.log(back);
      wx.navigateTo({
        url: `/pages/detail/detail?item=${JSON.stringify(shopList)}`
      })
    },
    onReady() {
     
    },
    //拆分数据
    getPhone(){
      let slicedShopList = this.data.shopList.slice(0, 6);
      let slicedShopLists = this.data.shopList.slice(6, 12);
      // console.log(slicedShopList);
      this.setData({
        phoneList: slicedShopList,
        phonesList: slicedShopLists
      });
    },
    
})